import { FMVCS } from "../../fgui/fmvc/FMVCS";
import ButtonTipsCtrl from "./ButtonTipsCtrl";
import ButtonTipsVO from "./ButtonTipsVO";

export default class ButtonTipsView extends FMVCS.FView {
    dataVO: ButtonTipsVO = null;
    clickHandlers() {
        return [
            [this._views[`btnClose`], this.onClose, this],
        ];
    }

    onOpenCallBack(){
        this.dataVO = ButtonTipsCtrl.data.vo;
        this.onFlush();
    }

    onBtn1CallBack(){
        this.dataVO.btn1CallBack();
        this.dataVO.btn1CallBack = () => {};
        this.onClose();
    }

    onBtn2CallBack(){
        this.dataVO.btn2CallBack();
        this.dataVO.btn2CallBack = () => {};
        this.onClose();
    }

    onBtn3CallBack(){
        this.dataVO.btn3CallBack();
        this.dataVO.btn3CallBack = () => {};
        this.onClose();
    }

    onFlush(type: string = `all`) {
        switch (type) {
            case `all`: {
                this._updateLblText();
                this._updateLblBtn1Text();
                this._updateLblBtn2Text();
                this._updateLblBtn3Text();
                this._updateButtonNum();
                break;
            }
        }
    }

    private _updateLblText() {
        let lbl = this._views[`lblText`].asLabel;
        lbl.text = this.dataVO.text;
    }

    private _updateLblBtn1Text() {
        let btn = this._views[`btnList`]._children[0];
        if(btn){
            btn.asCom.getChild(`lblText`).text = this.dataVO.btn1Text;
            btn.asButton.onClick(this.onBtn1CallBack, this);
        }
    }

    private _updateLblBtn2Text() {
        let btn = this._views[`btnList`]._children[1];
        if(btn){
            btn.asCom.getChild(`lblText`).text = this.dataVO.btn2Text;
            btn.asButton.onClick(this.onBtn2CallBack, this);
        }
    }

    private _updateLblBtn3Text() {
        let btn = this._views[`btnList`]._children[2];
        if(btn){
            btn.asCom.getChild(`lblText`).text = this.dataVO.btn3Text;
            btn.asButton.onClick(this.onBtn3CallBack, this);
        }
    }

    private _updateButtonNum(){
        let buttonList = this._views[`btnList`].asList;
        buttonList.numItems = this.dataVO.buttonNum;
    }
}